import {Injectable} from '@angular/core';
import {ApesModalService} from '@shared/apes/modal';
import {ApiService} from '@core/services/http/api.service';
import {ApesMessageService} from '@shared/apes/message';
import {ApesOaComponent} from '@shared/apes-oa';

@Injectable({
  providedIn: 'root'
})
export class OaService {

  constructor(private apiService: ApiService,
              private  msg: ApesMessageService,
              private modalService: ApesModalService,) {
  }

  openDialog(params: any, callback: any, dialog?: any): void {
    const openDialog = dialog ? dialog : ApesOaComponent;
    const dialogRef = this.modalService.create({
      apesWidth: '50vw',//800
      apesMaskClosable: true,
      apesTitle: params.label,
      // apesWrapClassName: 'modal-lg',
      apesContent: openDialog,
      apesComponentParams: params,
      apesFooter: [
        {
          label: '取消',
          type: 'default',
          onClick: () => {
            dialogRef.close();
          }
        },
        {
          label: '确定',
          type: 'primary',
          disabled: (componentInstance) => {
            return !componentInstance['form'].valid;
          },
          onClick: (componentInstance) => {
            dialogRef.destroy(componentInstance['modelData']);
          }
        }
      ]
    });

    // 调用前的回调
    dialogRef.afterOpen.subscribe(() => {});
    dialogRef.afterClose.subscribe((result) => callback(result));
  }


}
